package com.by.controller;

import com.by.bean.Horder;
import com.by.bean.Porder;
import com.by.common.bean.ResultBean;
import com.by.common.controller.BaseController;
import com.by.service.HorderService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
@RequestMapping("/v1")
@Api(tags = "货代订单管理")
public class HorderController extends BaseController {
    @Autowired
    HorderService horderService;
    @ApiOperation("获取编号")
    @PostMapping("/horder/getcode")
    public ResultBean gethcode(){
        String hcode="H"+System.currentTimeMillis() ;
        return success("获取编号",hcode);
    }
    @ApiOperation("保存订单")
    @PostMapping("/horder/save")
    public ResultBean  save(@RequestBody Horder data){
        int rs =horderService.save(data);
        if (rs==1) {
            return success("成功");
        }else {
            return fail("失败");
        }
    }
    @ApiOperation("查询订单")
    @PostMapping("/horder/query")
    public ResultBean query(@RequestBody Horder order){
        List list=horderService.query(order);
        return success("查询",list);
    }

    @ApiOperation("更新状态")
    @PostMapping("/horder/updateStatus")
    public ResultBean updateStatus(@RequestBody Horder order){
        order.setStatus(order.getStatus()+1);
        int rs=horderService.hUpdateStatus(order);
        return  success("成功" ,rs);
    }
}
